import { defineStore } from "pinia";

export const submenuStore = defineStore("menu", {
  state: () => {
    return {
      menus: [], // 顶部菜单
      subMenus: JSON.parse(sessionStorage.getItem("RJmenu")) || [], // 左侧菜单
      yjActive: sessionStorage.getItem("yjActive") == "null" ? '0' : sessionStorage.getItem("yjActive"), // 1级菜单选当前选中的
      rjBase: sessionStorage.getItem("rjBase") || '/', // 二级的baseurl
      isCollapse: false,
    };
  },
  getters: {
    // isCollapse:(state) => {return state.isCollapse}
  },
  actions: {
    setMenus(menus) {
      this.menus = menus;
    },
    setsubMenus(menus) {
      this.subMenus = menus;
      sessionStorage.setItem("RJmenu",JSON.stringify(this.subMenus));
    },
    setrjBase(base) {
      this.rjBase = base;
      sessionStorage.setItem("rjBase", base);
    },
    setyjActive(index){
      this.yjActive = index;
      sessionStorage.setItem("yjActive", index);
    },
    setisCollapse(type){
      this.isCollapse = type
    }
  },
});
